package engine

import (
	"sdn-executor/utils"
)

type MsgType string

const (
	MsgTypeCLI         MsgType = "CLI"
	MsgTypeNetconf     MsgType = "NETCONF"
	MsgTypeGNMICap     MsgType = "GNMICAP"
	MsgTypeGNMIGet     MsgType = "GNMIGET"
	MsgTypeGNMIUpdate  MsgType = "GNMIUPDATE"
	MsgTypeGNMIReplace MsgType = "GNMIREPLACE"
	MsgTypeGNMIDelete  MsgType = "GNMIDELETE"
)

type Message struct {
	Type      MsgType
	Pri       int
	ReadOnly  bool
	RequestId string
	Request   any
	Response  chan any
}

func NewMessage(typ MsgType, pri int, readOnly bool, request any) *Message {
	return &Message{
		Type:      typ,
		Pri:       pri,
		ReadOnly:  readOnly,
		RequestId: utils.RequestId(string(typ)),
		Request:   request,
		Response:  make(chan any, 1),
	}
}

func (m *Message) Priority() int {
	return m.Pri
}

func (m *Message) CloseChannel() {
	close(m.Response)
}
